﻿using System;
using System.Collections;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.UI.DataTypes;
namespace WEATHER.Modules.ONLINE
{
    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            ModuleSettingItem itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = "";
            itemSetting.Name = "CssClass";
            itemSetting.Description = "CssClass";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("CssClass", itemSetting);

            itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = "400";
            itemSetting.Name = "FrameHeight";
            itemSetting.Description = "FrameHeight";
            itemSetting.SortOrder = 2;
            this.BaseSettings.Add("FrameHeight", itemSetting);

            itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = "400";
            itemSetting.Name = "FrameWidth";
            itemSetting.Description = "FrameWidth";
            itemSetting.SortOrder = 3;
            this.BaseSettings.Add("FrameWidth", itemSetting);

            itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = "0";
            itemSetting.Name = "FrameBorder";
            itemSetting.Description = "FrameBorder";
            itemSetting.SortOrder = 4;
            this.BaseSettings.Add("FrameBorder", itemSetting);

            itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = "auto";
            itemSetting.Name = "Scrolling";
            itemSetting.Description = "Scrolling";
            itemSetting.SortOrder = 5;
            this.BaseSettings.Add("Scrolling", itemSetting);

            ArrayList list = new ArrayList();
            list.Add(new ListItem("AreaWeather", "AreaWeather"));
            list.Add(new ListItem("CurrentWeather", "CurrentWeather"));
            list.Add(new ListItem("ListProvinceWeather", "ListProvinceWeather"));
            list.Add(new ListItem("ProvinceWeather", "ProvinceWeather"));
            
            list.Add(new ListItem("ThoiTietDatLien24H", "ThoiTietDatLien24H"));
            list.Add(new ListItem("ThoiTietBien24H", "ThoiTietBien24H"));
            list.Add(new ListItem("DuBao10Ngay", "DuBao10Ngay"));
            list.Add(new ListItem("DuBaoThang", "DuBaoThang"));
            list.Add(new ListItem("DuBaoMua", "DuBaoMua"));
            
            list.Add(new ListItem("TTNH_BaoVaApThapNhietDoi", "TTNH_BaoVaApThapNhietDoi"));
            list.Add(new ListItem("TTNH_KhongKhiLanh", "TTNH_KhongKhiLanh"));
            list.Add(new ListItem("TTNH_NangNong", "TTNH_NangNong"));
            list.Add(new ListItem("TTNH_KhoHan", "TTNH_KhoHan"));
            
            list.Add(new ListItem("TVDB_ThongBaoLu", "TVDB_ThongBaoLu"));
            list.Add(new ListItem("TVDB_ThongBaoCan", "TVDB_ThongBaoCan"));
            list.Add(new ListItem("TVDB_ThongBaoXaNuocChongHan", "TVDB_ThongBaoXaNuocChongHan"));

            list.Add(new ListItem("DBHN_SongBacBo", "DBHN_SongBacBo"));
            list.Add(new ListItem("DBHN_SongTrungVaNamBo", "DBHN_SongTrungVaNamBo"));
            list.Add(new ListItem("DBHV_SongBacBo", "DBHV_SongBacBo"));
            list.Add(new ListItem("DBHV_SongTrungVaNamBo", "DBHV_SongTrungVaNamBo"));
            list.Add(new ListItem("DBT_SongBacBo", "DBT_SongBacBo"));
            list.Add(new ListItem("DBT_SongTrungVaNamBo", "DBT_SongTrungVaNamBo"));
            list.Add(new ListItem("DBM_SongBacBo", "DBM_SongBacBo"));
            list.Add(new ListItem("DBM_SongTrungVaNamBo", "DBM_SongTrungVaNamBo"));

            
            itemSetting = new ModuleSettingItem(new CustomListDataType(list, "Text", "Value"));
            itemSetting.Value = "AreaWeather";
            itemSetting.Name = "WeatherType";
            itemSetting.Description = "WeatherType";
            itemSetting.SortOrder = 6;
            this.BaseSettings.Add("WeatherType", itemSetting);


            itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = Guid.Empty.ToString();
            itemSetting.Name = "ModuleID";
            itemSetting.Description = "ModuleID";
            itemSetting.SortOrder = 7;
            this.BaseSettings.Add("WEATHER.ModuleID", itemSetting);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Hashtable settings = this.Settings;
            iframe.Attributes.Add("class", settings["CssClass"].ToString());
            iframe.Attributes.Add("height", settings["FrameHeight"].ToString());
            iframe.Attributes.Add("width", settings["FrameWidth"].ToString());
            iframe.Attributes.Add("frameborder", settings["FrameBorder"].ToString());
            iframe.Attributes.Add("scrolling", settings["Scrolling"].ToString());

            string weatherType = settings["WeatherType"].ToString();
            switch (weatherType)
            {
                case "AreaWeather":
                    iframe.Attributes.Add("src", "Modules/WEATHER.Modules.ONLINE/Pages/AreaWeather.aspx?mid=" + settings["WEATHER.ModuleID"]);    
                    break;
                case "CurrentWeather":
                    iframe.Attributes.Add("src", "Modules/WEATHER.Modules.ONLINE/Pages/ProvinceWeather.aspx?mid=" + settings["WEATHER.ModuleID"]);    
                    break;
                case "ListProvinceWeather":
                    iframe.Attributes.Add("src", "Modules/WEATHER.Modules.ONLINE/Pages/ListProvinceWeather.aspx?mid=" + settings["WEATHER.ModuleID"]);    
                    break;
                case "ProvinceWeather":
                    iframe.Attributes.Add("src", "Modules/WEATHER.Modules.ONLINE/Pages/ProvinceWeatherDetail.aspx?mid="  + settings["WEATHER.ModuleID"] + "&ProvinceCode=%2f21%2f92");
                    break;
                case "ThoiTietDatLien24H":
                case "ThoiTietBien24H":
                case "DuBao10Ngay":
                case "DuBaoThang":
                case "DuBaoMua":
                    iframe.Attributes.Add("src", "Modules/WEATHER.Modules.ONLINE/Pages/Meteor.aspx?mid="  + settings["WEATHER.ModuleID"] + "&MeteorWeatherType=" + weatherType);
                    break;
                case "DBHN_SongTrungVaNamBo":
                case "DBHV_SongTrungVaNamBo":
                case "DBT_SongTrungVaNamBo":
                case "DBM_SongTrungVaNamBo":
                    iframe.Attributes.Add("src", "Modules/WEATHER.Modules.ONLINE/Pages/HydrologicForecastWeather.aspx?mid=" + settings["WEATHER.ModuleID"] + "&HydrologicForecastWeatherType=" + weatherType);
                    break;
                case "DBHN_SongBacBo":
                case "DBHV_SongBacBo":
                case "DBT_SongBacBo":
                case "DBM_SongBacBo":
                    iframe.Attributes.Add("src", "Modules/WEATHER.Modules.ONLINE/Pages/HydrologicForecastWeather.aspx?mid=" + settings["WEATHER.ModuleID"] + "&HydrologicForecastWeatherType=" + weatherType);
                    break;
                default:
                    iframe.Attributes.Add("src", "Modules/WEATHER.Modules.ONLINE/Pages/DangerousWeather.aspx?mid="  + settings["WEATHER.ModuleID"] + "&DangerousWeatherType=" + weatherType);
                    break;
            }
        }
    }
}